package tencent.st1;

import java.util.*;

class Solution {
//给定一个只包含小写字母字符串，每次可以选择两个相同的字符删除，并在字符串结尾新增任意一个小写字母。
//请问最少多少次操作后，所有的字母都不相同？
//输入例子1:
//"abab"
//输出例子1:
//2
    public int minOperations (String str) {
        int result=0;
        Map<Character,Integer> map = new HashMap();
        for (int i = 0; i < str.length(); i++) {
            char key=str.charAt(i);
            int temp=map.getOrDefault(key,0);
            map.put(key,temp+1);
        }
        ArrayList<Character> onlyone = new ArrayList<>();
        for (char key:map.keySet()) {
            int temp=map.get(key);
            if(temp>1){
                if(temp%2==0){
                    result+=temp/2;
                }else {
                    result+=temp/2;
                    onlyone.add(key);
                }
            }else {
                onlyone.add(key);
            }
        }
        int len=onlyone.size();
        if(len+result>26){
            result+=result+len-26;
        }
        return result;
    }

    public static void main(String[] args) {
        Solution a = new Solution();
        int result=a.minOperations("abab");
        System.out.println(result);
    }
}
